//
// Created by none98 on 2021/9/16.
//

#ifndef LOGINSERVER_DISPATCHER_H
#define LOGINSERVER_DISPATCHER_H


#include <unordered_map>
#include <memory>
#include <Buffer.h>
#include <CallBacks.h>
#include <boost/asio/thread_pool.hpp>

class Service;
class GameServer;
class Dispatcher {
public:
    using callFunc = std::function<void()>;

    Dispatcher(const std::function<void(callFunc)> &func):
    submiter(func)
    {
    }

    ~Dispatcher() = default;
    void RegisterHandler(unsigned int type, Service* handler);
    void Dispatch(TcpConnectionPtr conn, Buffer* inputBuffer);

private:
    std::unordered_map<int,std::unique_ptr<Service>> handlers;
    std::function<void(callFunc)> submiter;
};


#endif //LOGINSERVER_DISPATCHER_H
